package io.bdmc.modules.bss.controller;

import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.bdmc.common.utils.MyPage;
import io.bdmc.common.utils.R;
import io.bdmc.modules.bss.entity.SmkDevice;
import io.bdmc.modules.bss.service.ISmkAlarmService;
import io.bdmc.modules.bss.service.ISmkDeviceService;
import io.bdmc.modules.bss.service.ISmkShopService;
import io.bdmc.modules.sys.controller.AbstractController;

@RestController
@RequestMapping(value = "/bss/home")
public class HomeController extends AbstractController{
    @Autowired
    private ISmkAlarmService _alarmSvs;
    @Autowired
    private ISmkShopService _shopSvs;
    @Autowired
    private ISmkDeviceService _devSvs;

    @PostMapping(value = "/chart")
    public R chart() {
        Long dept_id = getDeptId();
        MyPage<SmkDevice> myPage = new MyPage<SmkDevice>(1, 10);
        Map<String, Object> results = new HashMap<String, Object>();
        results.put("shopCount", _shopSvs.countByDepId(dept_id));
        results.put("devCount", _devSvs.countByDepId(myPage));
        results.put("alarmCount", _alarmSvs.homeAlarmSum(dept_id));
        results.put("alarmFullYearChart", _alarmSvs.homeAlarmYearChart(dept_id));
        results.put("alarmDeptDescTwoMonth", _alarmSvs.homeDeptAlarmDescTwoMonth(dept_id));
        results.put("placeAlarmSum", _alarmSvs.homePlaceAlarmSum(dept_id));
        results.put("fireAlarmReason", _alarmSvs.homeFireAlarmReasonSum(dept_id));
        results.put("hiddenAlarmPlace", _alarmSvs.homeHiddenAlarmPlace(dept_id));
        results.put("deptHiddenAlarmSum", _alarmSvs.homeDeptHiddenAlarmSum(dept_id));
        results.put("deptRealtimeAlarm", _alarmSvs.homeDeptRealtimeAlarm(dept_id));
        results.put("weekHoursAlarm", _alarmSvs.homeWeekHoursAlarm(dept_id));
        
        return R.ok().putData(results);
    }

    @PostMapping(value = "/sum")
    public R sum() {
        Long dept_id = getDeptId();
        Map<String, Object> results = new HashMap<String, Object>();
        results.put("allPlaceAlarmSum", _alarmSvs.allPlaceAlarmSum(dept_id));
         results.put("shopLatLngList", _shopSvs.getShopLatLng(dept_id));
         results.put("todayAlarmSum", _alarmSvs.todayAlarmSum(dept_id));
         results.put("todayAlarmDetail", _alarmSvs.todayAlarmDetail(dept_id));
         results.put("homeDeptHiddenAlarmSum", _alarmSvs.homeDeptHiddenAlarmSum(dept_id));
         results.put("yearAlarmReasonSum", _alarmSvs.yearAlarmReasonSum(dept_id));
        
        return R.ok().putData(results);
    }



}